<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <script>if (window !== top) top.location.replace(location.href);</script>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="${ctxPath}/assets/images/favicon.ico">
    <title>哈尔滨麻将快速计算平台</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-row">
    <div class="layui-col-sm3">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <div class="layui-col-sm6">
        <h1 class="site-h1" id="title" style="text-align: center;padding-left: 15%;padding-top: 25%;"></h1>
        <form class="layui-form" style="margin-top: 25%;" id="form1"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
            <div class="layui-form-item">
                <label class="layui-form-label">東</label>
                <div class="layui-input-block">
                    <select name="dong">
                        <option value="">请选择玩家</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">西</label>
                <div class="layui-input-block">
                    <select name="xi">
                        <option value="">请选择玩家</option>

                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">南</label>
                <div class="layui-input-block">
                    <select name="nan">
                        <option value="">请选择玩家</option>

                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">北</label>
                <div class="layui-input-block">
                    <select name="bei">
                        <option value="">请选择玩家</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" lay-submit="" class="layui-btn" lay-filter="tijiao">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
        </form>


        <form class="layui-form" id="form2">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="name"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" id="addPlayer" lay-submit lay-filter="addPlayer">添加玩家</button>
                </div>
            </div>
        </form>
    </div>





    <div class="layui-col-sm3">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
</div>

<script src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'element', 'admin', 'index', 'laytpl', 'element', 'notice', 'xnUtil', 'form'], function () {
        var $ = layui.jquery;
        var admin = layui.admin;
        var index = layui.index;
        var laytpl = layui.laytpl;
        var element = layui.element;
        var xnUtil = layui.xnUtil;
        var form = layui.form;
        var layer = layui.layer;

        /*        $("#start").click(function() {
                    location.href = getProjectUrl() + "start";
                });*/
        form.on('submit(addPlayer)',function (data) {
            admin.req(getProjectUrl() + "sysUser/add", JSON.stringify(data.field), function(res){
                layer.load(2);
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                });
            }, 'post');
        })

        form.on("submit(tijiao)",function(data) {
            console.log(data);
            console.log(data.field);
            data.field.session = "${count}";
            $.ajaxSettings.async = false;
            admin.req(getProjectUrl() + "session/add", JSON.stringify(data.field), function(res){
                layer.load(2);
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                });
            }, 'post');
            admin.req(getProjectUrl() + "score/add", JSON.stringify({session:data.field.session}), function(res){
                layer.load(2);
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                });
            }, 'post');
            $.ajaxSettings.async = true;
            location.href = getProjectUrl() + "mahjong";
        });


        admin.req(getProjectUrl() + 'sysUser/page', function (res) {
            console.log(res);
            for (let i = 0; i < res.data.length; i++) {
                $("[name='dong']").append("<option value=\"" + res.data[i].name + "\">" + res.data[i].name + "</option>");
                $("[name='xi']").append("<option value=\"" + res.data[i].name + "\">" + res.data[i].name + "</option>");
                $("[name='nan']").append("<option value=\"" + res.data[i].name + "\">" + res.data[i].name + "</option>");
                $("[name='bei']").append("<option value=\"" + res.data[i].name + "\">" + res.data[i].name + "</option>");
            }
            form.render("select");
        })



        var count = "${count}";
        var topcontent = "第" + count + "届O米杯麻将大赛";
        $("#title").html(topcontent);
        //缓存字典

        /*    // ajax渲染侧边栏
            admin.req(getProjectUrl() + 'getLoginUser', function(res){
              //将用户信息缓存到本地
              layui.data(admin.setter.tableName, {key: 'loginUser', value: res.data});

              //开启webSocket，一定要放在用户信息缓存后，否则取的还是上次的登录信息
              xnUtil.openWebSocket();
              //渲染顶部系统栏
              laytpl(topNav.innerHTML).render(res.data.apps, function (html) {
                $('#snowy-nav-top-box').append(html);
              });

              //渲染左侧菜单
              laytpl(sideNav.innerHTML).render(res.data.menus, function (html) {
                $('.layui-side-scroll').html(html);
                element.render('nav');
                // 加载页面
                index.loadHome({
                  menuPath: getProjectUrl() + 'other/welcomeHtml',
                  menuName: '<i class="layui-icon layui-icon-home"></i>',
                  // 刷新后默认打开上次的页签
                  loadSetting: true,
                  // 并且只打开最后一个页签
                  onlyLast: true
                });
              });
            });*/
    });
</script>
</body>
</html>
